home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2006 October / wn148cd2.iso / Windows / Travailler / QuickZip / quickzip_460013.exe / {app} / Scripts / Syncthronize.akp < prev    next >
Text File  |  2003-05-11  |  3KB  |  82 lines

  1. //Compare and update the files in <Dir1> and <Dir2>.
  2. //Backup overwrited file to <BackupChanges>.
  3. const Dir1 = 'C:\1';
  4.       Dir2 = 'C:\2';
  5.       BackupChanges = 'C:\Temp\Backup.zip';
  6.       SubDir = True;
  7. var Content1, Content2 : TStrings;
  8.     Path1,Path2 : String;
  9. procedure PollDirectoryContents;
  10. var i : integer;
  11. begin
  12.   Path1 := AppendSlash(Dir1);
  13.   Path2 := AppendSlash(Dir2);
  14.   Content1.AddStrings(PollFileList(Path1+'*',SubDir));
  15.   Content2.AddStrings(PollFileList(Path2+'*',SubDir));
  16.   for i := 0 to Content1.count -1 do
  17.      content1.strings[i] := Copy(content1.strings[i], Length(Path1) + 1, length(content1.strings[i]) - Length(Path1));
  18.   for i := 0 to Content2.count -1 do
  19.      content2.strings[i] := Copy(content2.strings[i], Length(Path2) + 1, length(content2.strings[i]) - Length(Path2));
  20. end;
  21. procedure CheckNewFiles;
  22. var i : integer;
  23. begin
  24.   Writeln('Looking for new files...');
  25.   For i := 0 to Content1.count -1 do
  26.     begin
  27.       if not Fileexists(Path2 + Content1.strings[i]) then
  28.          begin
  29.            Writeln(Path1 + Content1.strings[i] + ' -> ' + Path2);
  30.            CopyFile(Path1 + Content1.strings[i],Path2 + Content1.strings[i] );
  31.          end;
  32.     end;
  33.    For i := 0 to Content2.count -1 do
  34.     begin
  35.       if not Fileexists(Path1 + Content2.strings[i]) then
  36.          begin
  37.            Writeln(Path2 + Content2.strings[i] + ' -> ' + Path1);
  38.            CopyFile(Path2 + Content2.strings[i],Path1 + Content2.strings[i]);
  39.          end;
  40.     end;
  41.  
  42. end;
  43.  
  44. procedure CompareFileDate;
  45. var i,j : integer;
  46. begin
  47.   Open(BackupChanges);
  48.   UseAddPath(True);
  49.   UseVerCtrl(True);
  50.   Writeln('Comparing existing files...');
  51.   For i := 0 to Content1.count -1 do
  52.   begin
  53.    j := Content2.Indexof(Content1.strings[i]);
  54.    if j <> -1 then
  55.     begin
  56.       if GetFileDatetime(Path1+Content1.strings[i]) > GetFileDatetime(Path2+Content2.strings[j]) then
  57.          begin
  58.            Writeln(Path1+Content1.strings[i] + ' -> ' + Path2+Content2.strings[j]);
  59.            Add(Path2+Content2.strings[j]);
  60.            DoAdd;
  61.            CopyFile(Path1+Content1.strings[i],Path2+Content2.strings[j]);
  62.          end else
  63.       if GetFileDatetime(Path1+Content1.strings[i]) < GetFileDatetime(Path2+Content2.strings[j]) then
  64.          begin
  65.            Writeln(Path1+Content1.strings[i] + ' <- ' + Path2+Content2.strings[j]);
  66.            Add(Path1+Content1.strings[i]);
  67.            DoAdd;
  68.            CopyFile(Path2+Content2.strings[j],Path1+Content1.strings[i]);
  69.          end;
  70.     end;
  71.   end;
  72. end;
  73.  
  74. begin
  75.   Content1 := TStringList.create();
  76.   Content2 := TStringList.create();
  77.   PollDirectoryContents;
  78.   CheckNewFiles;
  79.   CompareFileDate;
  80.   Writeln('Completed!');
  81. end.
  82.